import { ref } from "vue"
import { useReady } from "@usehook"

//在app.vue中赋值
export let keepaliveRef = ref(null)
const { ready, changeReady } = useReady(500)
//移除keepalive的公共方法
export const removeKeepalive = (key, immediate = true) => {
    // 刷新时，immediate为false，防止快速刷新导致的抖动
    // 关闭tagMenu时，immediate为true，暂时没发现有问题
    if (!immediate) {
        if (!ready.value) return
        changeReady()
    }
    keepaliveRef.value.removeKeepalive(key)
}
//获取当前keepalive的组件名称=>key
export const getKeepaliveKeys = () => {
    return keepaliveRef.value.keys
}